package com.example.hashring;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;

public class ArrayMain<T> {

    private static List lista = new ArrayList();

    private static List listb = new ArrayList();

    private static List listc = new ArrayList();

    public void add(T t){
        double v = t.hashCode() % Math.pow(2, 32);

        Double a = lista.hashCode() % Math.pow(2, 32);
        Double b = listb.hashCode() % Math.pow(2, 32);
        Double c = listc.hashCode() % Math.pow(2, 32);
        List<Double> collect = Arrays.asList(a, b, c).stream().sorted().collect(Collectors.toList());

        Double aDouble =collect.stream().filter(e -> {
            return e > v;
        }).findFirst().orElse(collect.stream().findFirst().get());
        if(aDouble.equals(a)){
            lista.add(t);
        }else if(aDouble.equals(b)){
            listb.add(t);
        }else if(aDouble.equals(c)){
            listc.add(t);
        } else {
            System.err.println("运行出错");
        }
    }

    @Override
    public String toString() {
        return "lista:"+lista.size()+",listb:"+listb.size()+",listc:"+listc.size();
    }
}
